package com.mdx.zhizhao.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.mdx.zhizhao.domain.Job;
import com.mdx.zhizhao.persistence.JobMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class JobService {
    @Autowired
    private JobMapper jobMapper;
    public void insertJob(Job job){
        jobMapper.insert(job);
    }
    public void updateJob(Job job){
        jobMapper.updateById(job);
    }
    public void deleteJob(String jobId){
        jobMapper.deleteById(jobId);
    }
    public Job selectJob(String jobId){
        return jobMapper.selectById(jobId);
    }
     public List<Job> selectJobByEnterpriseId(String enterpriseId){
         QueryWrapper<Job> queryWrapper = new QueryWrapper<Job>();
         queryWrapper.eq("enterpriseid", enterpriseId);
         List<Job> job = jobMapper.selectList(queryWrapper);
        return jobMapper.selectList(queryWrapper);
    }
      // 新增的根据 jobname 查找 List<String> enterpriseid 的函数
    public List<String> selectEnterpriseIdsByJobName(String jobName) {
        QueryWrapper<Job> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("jobname", jobName);
        List<Job> jobs = jobMapper.selectList(queryWrapper);
        List<String> enterpriseIds = new ArrayList<>();
        for (Job job : jobs) {
            enterpriseIds.add(job.getEnterpriseid());
        }
        return enterpriseIds;
    }
     // 新增的根据 jobname 和 enterpriseid 查找一个 Job 的函数
    public Job selectJobByJobNameAndEnterpriseId(String jobName, String enterpriseId) {
        QueryWrapper<Job> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("jobname", jobName);
        queryWrapper.eq("enterpriseid", enterpriseId);
        return jobMapper.selectOne(queryWrapper);
    }
}
